package com.woniuxy.handler;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.pojo.Grade;
import com.woniuxy.pojo.PageInfo;
import com.woniuxy.pojo.User;
import com.woniuxy.service.GradeService;
import com.woniuxy.service.UserService;

import lombok.Data;

@Controller
@RequestMapping("/grade")
@Data
public class GradeHandler {
	@Resource
	private GradeService gradeService;
	@Resource
	private UserService userService;

	@RequestMapping("/show")
	@ResponseBody
	public PageInfo show(int pageNumber) {
		// pageNumber传入的页码
		PageInfo pageInfo = gradeService.ShowAllByPage(pageNumber);
		return pageInfo;

	}

	// 根据用户权限(老师)查用户
	public List<User> findAllByRole_name() {
		List<User> list = userService.findAllByRole_name("student");
		return list;

	}

	// 添加信息
	public boolean add(Grade grade) {
		int i = gradeService.add(grade);
		if (i > 0) {
			return true;
		}
		return false;
	}

	// 删除班级
	public boolean delete(int grade_id) {
		int i = gradeService.delete(grade_id);
		if (i > 0) {
			// 返回值不为0才表示删除成功
			return true;
		}
		return false;

	}

	// 显示所有班级
	public List<Grade> all() {
		return gradeService.all();
	}
}
